package com.leadingsoft.pwxk.task;

import java.util.concurrent.CountDownLatch;

import com.leadingsoft.pwxk.services.LatestDataService;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class LatestDataTask implements Runnable {

	LatestDataService latestDataService;

	private CountDownLatch countDownLatch;

	public LatestDataTask(LatestDataService latestDataService, CountDownLatch countDownLatch) {
		this.latestDataService = latestDataService;
		this.countDownLatch = countDownLatch;
	}

	@Override
	public void run() {
		try {
			// 进行最新数据整理之前，必须等待其他线程跑完
			countDownLatch.await();
			log.info("进入收集最新企业数据任务");
			latestDataService.saveLatestData();
			log.info("退出收集最新企业数据任务");
		} catch (Exception e) {
			log.error("收集最新企业数据异常：" + e.getMessage(), e);
		}

	}

	public CountDownLatch getCountDownLatch() {
		return countDownLatch;
	}

	public void setCountDownLatch(CountDownLatch countDownLatch) {
		this.countDownLatch = countDownLatch;
	}

}
